<php>
$this->display(tpl('head')); 
</php>
<style>

	.layui-table {
	    width: 95%;
	    background-color: #fff;
	    color: #666;
	    margin:0 2.5%;
	}
	.layui-table td, .layui-table th {
	    position: relative;
	    padding: 9px 5px;
	    min-height: 20px;
	    line-height: 20px;
	    font-size: 14px;
	    text-align: center;
	}
	.layui-table td:nth-child(2), .layui-table th:nth-child(2){
	    text-align:left;
	}
	.layui-form .layui-form-switch {
	    width: 65px;
	    margin-top: 0;
	}
	.layui-form .layui-form-switch em {
	    width: 50px;
	}
	.layui-form  .layui-form-onswitch i {
	    left: 55px;
	    background-color: #fff;
	}
</style>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  	<legend>用户管理</legend>
</fieldset>
<form class="layui-form" id="from" method="post" action="">
	<table class="layui-table " cellspacing="0" cellpadding="0" border="0"  lay-filter="demoEvent">
		<thead>
			<tr>
				<th  width="50"></th>
				<th>UID</th>
				<th>用户名</th>
				<th>所在用户组</th>
				<th>Email</th>
				<th>手机</th>
				<th>积分</th>
				<th>注册时间</th>
				<th width="100">审核</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<foreach array="data">
		<php>
			
				$row['regtime']=date('Y-m-d H:i:s',$row['regtime']);
				$state= $row['state']===1 ? "checked" : '';
		</php>

			<tr data-index="{{$row['uid'] }}" id="list_{{$row['uid'] }}">
				<td align="center"> <input lay-skin="primary" type="checkbox" name="uiddb[]" value="{{$row['uid'] }}"></td>
				<td data-field="id"><div class="layui-table-cell laytable-cell-1-id">{{$row['uid'] }}</div></td>
				<td data-field="username"><div class="layui-table-cell laytable-cell-1-title">{{$row['username'] }}</div></td>
				<td><div class="layui-table-cell ">{{$row['groupname'] }}</div></td>
				<td><div class="layui-table-cell ">{{$row['email'] }}</div></td>
				<td><div class="layui-table-cell ">{{$row['mobile'] }}</div></td>
				<td><div class="layui-table-cell " lay-event="setSign" style="cursor: pointer;">{{$row['integral'] }}</div></td>
				<td><div class="layui-table-cell ">{{$row['regtime'] }}</div></td>
				<td>
					<div class="layui-table-cell ">
						<div class="layui-form-item">
							<div class="layui-input-block">
								<input {{$state  }} lay-skin="switch" lay-filter="state" uid="{{$row['uid'] }}" lay-text="已审核|未审核" type="checkbox" value="1">
							</div>
						</div>
					</div>
				</td>
				<td>
					<div class="layui-table-cell ">
						<a class="layui-btn layui-btn-sm" href="/admin/user/post_yz_email/uid_{{$row['uid'] }}" onclick="return confirm('此操作会向此用户发送一封重置密码的邮件，并且该会员审核状态为已审。是否确定发送')">email重置密码</a>
						<a class="layui-btn layui-btn-sm" href="/admin/user/edit/uid_{{$row['uid'] }}">编辑</a>
						<a class="layui-btn layui-btn-sm layui-btn-danger" href="JavaScript:void(0)" uid="{{$row['uid'] }}" lay-submit='' lay-filter="del">删除</a>
					</div>
				</td>
			</tr>
			</foreach>
		</tbody>
	</table>
	<div class="button" style=" margin-top: 20px;">
		<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('1')">全选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('-1')">反选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" 	onclick="return all_checkbox_check('0')">取消选择</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="state" value="1" onclick="return post('state')">通过审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger"	name="state" value="0" onclick="return post('state')">取消审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" onclick="return post('del')">批量删除</button>
	</div>
</from>

<div class="page">
	{{$Get_Page }}
</div>

<script>
	function all_checkbox_check(type){
		let class_box=$('input[lay-skin="primary"]');
		for(var i=0;i<class_box.length;i++){
			let box=class_box[i];
			if(type=="1"){//全选
				box.checked=true;
			}else if(type=="0"){//全不选
				box.checked=false;
			}else if(type=="-1"){//反选
				if(box.checked==true){
					box.checked=false;
				}else{
					box.checked=true;
				}
			}
		}
		form.render('checkbox');
		return false;
	}  
	function post(a){
		if(a==='state'){
			$('#from').attr('action','/admin/user/state');
		}else{
			$('#from').attr('action','/admin/user/del');
		}
	}
	let form;
	layui.use(['form','table','layer'], function() {
		form = layui.form;
		var table = layui.table;
  		var layer = layui.layer;
		form.on('switch(state)', function(obj){
		  	if(obj.elem.checked==true){
		  		var state=1;
		  	}else{
		  		var state=0;
		  	}
		  	var t=this;
		  	$.ajax({
				url:"/admin/user/state",
				type: 'POST',
				data:{'state':state,'uid':obj.elem.getAttribute("uid"),'json':true},
				dataType: 'json',
				success: function(data){
					if(data.code==0){
						if(obj.elem.checked==true){
					  		layer.tips("已完成审核", obj.othis);
					  	}else{
					  		layer.tips("已取消审核", obj.othis);
					  	}
					}else{
						layer.tips(data.content+',修改无效', obj.othis);
					}
					
				}
			})
		});
		
		form.on('submit(del)', function(obj){
			var uid=obj.elem.getAttribute("uid")
		  	$.ajax({
				url:"/admin/user/del",
				type: 'POST',
				data:{'uid':uid,'json':true},
				dataType: 'json',
				success: function(data){
					if(data.code==='0'){
						$('#list_'+uid).remove();
					}else{
						layer.msg(data.text);
					}
				}
			})
	  	});
	});
</script>
<php>
$this->display(tpl('foot')); 
</php>
